package Data;

import android.graphics.Bitmap;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class BasicData {
    public static final int 上衣 = 0;
    public static final int 裤子 = 1;
    public static final int 裙子 = 2;
    public static final int 其他衣物 = 4;

    public  static final int  口红= 0;
    public static final int 散粉 = 1;
    public static final int 腮红 = 2;
    public static final int 粉底 = 3;
    public static final int 眼影 = 4;
    public static final int 眼线 = 5;
    public static final int  护肤品= 6;
    public  static  final  int 其他化妆品=7;

    public  static final int  双肩包= 0;
    public static final int 斜挎包 = 1;
    public static final int 手提包 = 2;
    public static final int 钱包 = 3;
    public static final int 其他包包 = 4;

    public  static final int  凉鞋= 0;
    public static final int 皮鞋 = 1;
    public static final int 运动鞋 = 2;
    public static final int 高跟鞋 = 3;
    public static final int 休闲鞋 = 4;
    public static final int 靴子 = 5;
    public static final int  其他鞋子= 6;


    public  static final int  耳饰= 0;
    public static final int 颈饰 = 1;
    public static final int 手饰 = 2;
    public static final int 发饰 = 3;
    public static final int 其它饰品 = 4;
    String category;
     int Type;
     String Name,Brand,Tag;
     Date Date;
     double Price;
     Bitmap Image=null;

public BasicData()
{

}


private static String StringDateFound(String l)
{
    String t;
    if( l.startsWith("d:"))
    {
        t= l.substring(2);
        return t;
    }
    else
        return null;

}
private static String StringTagFound(String l)
{
    String t;
    if( l.startsWith("t:"))
    {
        t= l.substring(2);
        return t;
    }
    return null;
}

public static BasicData StringToData(String line)
{
    String[] mustbe= StringDealer.PickUp(line,'{','}');
    String[] maybe= StringDealer.PickUp(line,'(',')');
    int type;
    double price;
    BasicData data;
    if(mustbe.length==5)
    {
        try {
            price=Double.valueOf(mustbe[4]);
            type=Integer.valueOf(mustbe[1]);
            data=new BasicData(mustbe[0],type,price,mustbe[3], mustbe[2],null,null,null);
            if(maybe.length<=2)
            {
                String d=null,t=null;
                for(int i=0;i<maybe.length;i++)
                {
                    String temp=maybe[i];
                    temp=   StringDateFound(temp);
                    if(temp!=null)
                    {
                        d=temp;
                        break;
                    }
                }
                for(int i=0;i<maybe.length;i++)
                {
                    String temp=maybe[i];
                    temp=   StringTagFound(temp);
                    if(temp!=null)
                    {
                        t=temp;
                        break;
                    }
                }
                data.setTag(t);
                if(d!=null)
                d+=" 00:00:00";
                data.setDate(StringDealer.strToDateLong(d));
                return data;
            }
            else
                return null;

        }catch (Exception ex)
        {
            return null;
        }
    }
    else
        return null;


}

    @Override
    public String toString() {
        return StringDealer.DataToString(this);
    }
    public  BasicData(@NonNull String category, @NonNull int type, @NonNull double price, @NonNull String name, @NonNull String Brand, @Nullable Date date,@Nullable Bitmap img,@Nullable String tag)
{
    this.category=category;
    this.setType(type);
    this.setBrand(Brand);
    this.setDate(date);
    this.setName(name);
    this.setPrice(price);
    this.setImage(img);
    setTag(tag);
}

    public void setCategory(String category) {
        this.category = category;
    }
    public  String DateStr()
{
    if(getDate()==null)
        return  null;
    Calendar cal = Calendar.getInstance();
    cal.setTime(getDate());
    return String.format("%04d-%02d-%02d 00:00:00",cal.get(Calendar.YEAR),cal.get(Calendar.MONTH),cal.get(Calendar.DAY_OF_MONTH));
}

    public String getTag() {
        return Tag;
    }

    public void setTag(String tag) {
        this.Tag = tag;
    }

    public String getCategory() {
        return category;
    }

    public String getID()
{
    return category+"-"+String.valueOf(getType())+"-"+getName()+"-"+getBrand();
}

    public Bitmap getImage() {
        return Image;
    }

    public void setImage(Bitmap image) {
        Image = image;
    }

    public java.util.Date getDate() {
        return Date;
    }

    public void setDate(java.util.Date date) {
        Date = date;
    }

    public double getPrice() {
        return Price;
    }

    public void setPrice(double price) {
        Price = price;
    }

    public String getName() {
        return Name;
    }

    public void setName(String name) {
        Name = name;
    }

    public int getType() {
        return Type;
    }

    public void setType(int type) {
        Type = type;
    }

    public String getBrand() {
        return Brand;
    }

    public void setBrand(String brand) {
        Brand = brand;
    }
}
